import Primary from './Primary'
import * as actions from '../../redux/actions/PrimaryAction'
import * as globalActions from '../../redux/actions/GlobalAction'
import { SimpleType, StoreState } from '../../redux/Types'
import { Dispatch } from 'redux'
import { connect } from 'react-redux'


export function mapStateToProps({ primary: { data, loading }, setting: { categorys, bands } }: StoreState) {
  return {
    data,
    loading,
    categorys,
    bands
  }
}
export function mapDispatchToProps(dispatch: Dispatch<actions.PrimaryAction | globalActions.GlobalAction>) {
  return {
    list: (data: SimpleType, page: any) => {
      dispatch(actions.page(page))
      dispatch(actions.getPrimaryList(data))
    },
    record: (record: any) => {
      const { id, no} = record
      dispatch(actions.recordPrimary({ sampleId: id }))
      dispatch(globalActions.recordBand({ id, no }))
      dispatch(globalActions.recordSample({ id: no }))
      dispatch(globalActions.getSampleImgs({ sampleId: id }))
    }
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(Primary)